_zimfw_check_version() {
  if (( ${1} )); then
    if (( ${2} )); then
      # background check
      if [[ -w ${_zversion_target:h} ]]; then
        print -R ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \
            https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &!
      fi
    else
      # foreground check
      local tags
      tags=$(command git ls-remote --tags --refs --sort=-v:refname https://github.com/zimfw/zimfw.git 'v*') || return 1
      >! ${_zversion_target} <<<${${${(f)tags}##*v}[1]} || return 1
    fi
  fi
  if [[ -f ${_zversion_target} ]]; then
    local -r zlatest_version=$(<${_zversion_target})
    if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
      _zimfw_print -u2 -R $'<%= yellow %>Latest zimfw version is <%= bold %>'${zlatest_version}$'<%= normalyellow %>. You\'re using version <%= bold %>'${_zversion}$'<%= normalyellow %>. Run <%= bold %>zimfw upgrade<%= normalyellow %> to upgrade.<%= normal %>'
      return 4
    fi
  fi
}
